<template>
  <div class="app-container" style="">
    <div class="search-header">
      <el-form ref="form" :model="form" label-width="80px" class="form-block">
        <el-form-item label="线路名称">
          <el-input v-model="form.name" style="display:block" />
        </el-form-item>
        <el-form-item label="线路类型">
          <el-select v-model="form.region" placeholder="请选择线路类型">
            <el-option label="普通线路" value="shanghai" />
            <el-option label="BRT线路" value="beijing" />
          </el-select>
        </el-form-item>
        <el-form-item label="线路公司">
          <el-select v-model="form.region" placeholder="请选择线路公司">
            <el-option label="公司1" value="shanghai" />
            <el-option label="公司2" value="beijing" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="content">
      <el-row style="padding:20px">
        <el-button type="primary" size="small" icon="el-icon-plus" @click="add_line">新增线路</el-button>

      </el-row>
      <el-table
        v-loading="listLoading"
        :data="list"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >
        <el-table-column align="center" label="ID" width="95">
          <template slot-scope="scope">
            {{ scope.$index }}
          </template>
        </el-table-column>
        <el-table-column label="Title">
          <template slot-scope="scope">
            {{ scope.row.title }}
          </template>
        </el-table-column>
        <el-table-column label="Author" width="110" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.author }}</span>
          </template>
        </el-table-column>
        <el-table-column label="Pageviews" width="110" align="center">
          <template slot-scope="scope">
            {{ scope.row.pageviews }}
          </template>
        </el-table-column>
        <el-table-column class-name="status-col" label="Status" width="110" align="center">
          <template slot-scope="scope">
            <el-tag :type="scope.row.status | statusFilter">{{ scope.row.status }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="created_at" label="Display_time" width="200">
          <template slot-scope="scope">
            <i class="el-icon-time" />
            <span>{{ scope.row.display_time }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>

  </div>
</template>

<script>
import { getList } from '@/api/table'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      list: null,
      listLoading: true
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    add_line() {
      this.$router.push({ path: '/line/add_line' })
    },
    onSubmit() {
      console.log('submit!')
    },
    fetchData() {
      this.listLoading = true
      getList().then(response => {
        this.list = response.data.items
        this.listLoading = false
      })
    }
  }
}
</script>
<style scoped>
.app-container{
  background:#f0f2f5;
}
.search-header{
  background: #fff;
  padding: 10px 20px;
  margin: 10px 10px;
  display: flex;
}
.form-block {
  display:flex;
  padding: 10px 20px;
  margin: 10px 0;
}
.content{
  margin: 10px 10px;
   background: #fff;

}
</style>
